package se.rende.schema2ical.client;

public class PassTime {
	private char name;
	private String fromTime;
	private String toTime;

	public PassTime(Character name, String fromTime, String toTime) {
		super();
		this.name = name;
		this.fromTime = fromTime;
		this.toTime = toTime;
	}
	
	public char getName() {
		return name;
	}

	public void setName(char name) {
		this.name = name;
	}
	
	public String getFromTime() {
		return fromTime;
	}
	
	public void setFromTime(String fromTime) {
		this.fromTime = fromTime;
	}
	
	public String getToTime() {
		return toTime;
	}
	
	public void setToTime(String toTime) {
		this.toTime = toTime;
	}

	public String getFromTimeHHmm() {
		return asHHmm(getFromTime());
	}

	public String getToTimeHHmm() {
		return asHHmm(getToTime());
	}

	private String asHHmm(String s) {
		if (s.contains(":")) {
			String[] parts = s.split(":");
			return leftPadTo(parts[0], 2) + parts[1];
		} else if (s.length() > 2) {
			return leftPadTo(s, 4);
		} else {
			return leftPadTo(s + "00", 4);
		}
	}

	private String leftPadTo(String s, int n) {
		String padded = "0000000000000" + s;
		return padded.substring(padded.length() - n);
	}
}
